/**
 * Created by root on 2017-05-12.
 */
var config = {
    baseUrl : "",
    devUrl: "http://121.42.165.44/ksd-app",
    goodsImgUrl : "http://121.42.165.44/ksd-app/static/resources/goodsImg/",
    success: 200
}

/*拼接商品图片路径*/
template.defaults.imports.goodsImgFun = function (imgUrl) {
    if(imgUrl == '') {
        return null;
    }
    else {
        return config.goodsImgUrl + imgUrl;
    }
}

/*获取用户级别的名称*/
template.defaults.imports.getUserClassName = function(userClass){
    var userClassName = '';
    switch (userClass){
        case 0: userClassName='普通会员'; break;
        case 1: userClassName='一星会员'; break;
        case 2: userClassName='二星会员'; break;
        case 3: userClassName='三星会员'; break;
        case 99: userClassName='运营中心会员'; break;
        case 80: userClassName='钻石会员'; break;
        case 81: userClassName='金钻会员'; break;
        case 82: userClassName='宝石会员'; break;
        default :userClassName = userClass; break;
    }
    return userClassName;
}

/*账户名称*/
template.defaults.imports.getAccountName = function(accountId){
    var accountName = '';
    switch (accountId){
        case 0: accountName='总积分数账户'; break;
        case 1: accountName='本金积分'; break;
        case 2: accountName='产品积分账户'; break;
        case 3: accountName='利润积分'; break;
        case 4: accountName='业绩账户'; break;
        case 5: accountName='指定积分数'; break;
        case 6: accountName='消费币账户'; break;
        case 7: accountName='冻结积分'; break;
        case 8: accountName='福利点'; break;
        case 21: accountName='运营中心本金账户'; break;
        case 23: accountName='运营中心利润账户'; break;
        case 24: accountName='运营中心业绩账户'; break;
        case 31: accountName='本金资产包账户'; break;
        case 32: accountName='收益资产包账户'; break;
        case 33: accountName='业绩资产包账户'; break;
        default :accountName = accountId; break;
    }
    return accountName;
}

// 时间格式化
template.defaults.imports.formatDate = function (purchaseTime, formatStr){
    var newDate = new Date();
    newDate.setTime(purchaseTime);
    return  newDate.format(formatStr);
    //return purchaseTime;
}

// 封装时间函数
/*yyyy-MM-dd
* yyyy-MM-dd h:m:s
* */
Date.prototype.format = function(format) {
    var date = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S+": this.getMilliseconds()
    };
    if (/(y+)/i.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    for (var k in date) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1
                ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
        }
    }
    return format;
}
